//
//  RealNameHeaderView.m
//  PigMarket
//
//  Created by mac on 2019/3/22.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "RealNameHeaderView.h"

@interface RealNameHeaderView ()
#define TextGrayColor [UIColor colorWithHexString:@"#939393"]

@end
@implementation RealNameHeaderView

#pragma mark - init method
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
        [self initLayout];
        [self addBgImgGesture];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self addSubview:self.bgImgView];
    [self.bgImgView addSubview:self.realNameStatusLab];
    [self.bgImgView addSubview:self.nameLab];
    [self.bgImgView addSubview:self.idCardNuLab];
    [self.bgImgView addSubview:self.limitTimeLab];
    [self.bgImgView addSubview:self.detailLimitTimeLab];
}

- (void)initLayout {
    // 布局子控件
    [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.mas_centerY);
        make.centerX.mas_equalTo(self.mas_centerX);
    }];
    [self.realNameStatusLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.bgImgView).offset(20);
        make.right.mas_equalTo(self.bgImgView.mas_right).offset(-20);
        make.size.mas_equalTo(CGSizeMake(40, 20));
    }];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.bgImgView).offset(26);
        make.top.mas_equalTo(self.bgImgView).offset(60);
        make.height.mas_equalTo(30);
    }];
    [self.idCardNuLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLab.mas_left);
        make.top.mas_equalTo(self.nameLab.mas_bottom).offset(14);
        make.right.mas_equalTo(self.bgImgView).offset(-60);
    }];
    [self.limitTimeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLab.mas_left);
        make.top.mas_equalTo(self.idCardNuLab.mas_bottom).offset(34);
        make.height.mas_equalTo(20);
    }];
    [self.detailLimitTimeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.limitTimeLab.mas_right).offset(20);
        make.bottom.mas_equalTo(self.limitTimeLab.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(130, 22));
    }];
}


- (void)addBgImgGesture {
    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(detailRealNameTap:)];
 
    [self.bgImgView addGestureRecognizer:tapRecognizer];
    
}


- (void)detailRealNameTap:(UIGestureRecognizer *)sender {
    
    if (self.detailRealNameBlock) {
        self.detailRealNameBlock();
    }
}


#pragma mark - setter methods

- (void)setNameModel:(RealName *)nameModel
{
    if ([nameModel.status intValue] == 1) {//通过实名认证
        
        self.realNameStatusLab.text = @"已实名";
        self.nameLab.text = nameModel.memberName;
        self.idCardNuLab.text = nameModel.idCard;
        self.detailLimitTimeLab.text = nameModel.idCardTerm;
        self.bgImgView.image = [UIImage imageNamed:@"user_realname_already"];
        
        self.nameLab.textColor = self.idCardNuLab.textColor = self.detailLimitTimeLab.textColor = self.limitTimeLab.textColor = KWhiteColor;
        self.realNameStatusLab.textColor = UIColorFromRGB(0x33B9B7);
        
        
        
    }else {
        self.realNameStatusLab.text = @"未实名";
        self.nameLab.text = @"姓名";
        self.detailLimitTimeLab.text = @"-- -- ----";
        self.limitTimeLab.text = @"有效期";
        self.idCardNuLab.text = @"------  ---------  ----";
        self.bgImgView.image = [UIImage imageNamed:@"user_realname_no"];
        
        self.nameLab.textColor = self.idCardNuLab.textColor = self.detailLimitTimeLab.textColor = self.limitTimeLab.textColor = UIColorFromRGB(0x939393);

        self.realNameStatusLab.textColor = UIColorFromRGB(0xC1C1C1);
        
    }
}

#pragma mark - getter methods

- (UIImageView *)bgImgView {
    if (!_bgImgView) {
        _bgImgView  = [[UIImageView alloc] init];
        _bgImgView.image = [UIImage imageNamed:@"user_realname_no"];
        _bgImgView.userInteractionEnabled = YES;
    }
    return _bgImgView;
}


- (UILabel *)realNameStatusLab {
    if (!_realNameStatusLab) {
        _realNameStatusLab = [[UILabel alloc] init];
        _realNameStatusLab.textColor = UIColorFromRGB(0xC1C1C1);
        _realNameStatusLab.font = [UIFont systemFontOfSize:10];
        _realNameStatusLab.layer.cornerRadius = 2;
        _realNameStatusLab.layer.masksToBounds = YES;
        _realNameStatusLab.backgroundColor = [UIColor whiteColor];
        _realNameStatusLab.textAlignment = NSTextAlignmentCenter;
        _realNameStatusLab.text = @"未实名";
    }
    return _realNameStatusLab;
}


- (UILabel *)nameLab {
    if (!_nameLab) {
        _nameLab = [[UILabel alloc] init];
        _nameLab.textColor = TextGrayColor;
        _nameLab.font = [UIFont largerFont];
        _nameLab.text = @"姓名";
    }
    return _nameLab;
}


- (UILabel *)idCardNuLab {
    if (!_idCardNuLab) {
        _idCardNuLab = [[UILabel alloc] init];
        _idCardNuLab.textColor = UIColorFromRGB(0x939393);
        _idCardNuLab.font = [UIFont systemFontOfSize:24];
        _idCardNuLab.text = @"-----  --------  ----";
    }
    return _idCardNuLab;
}


- (UILabel *)limitTimeLab {
    if (!_limitTimeLab) {
        _limitTimeLab = [[UILabel alloc] init];
        _limitTimeLab.textColor = UIColorFromRGB(0x939393);
        _limitTimeLab.font = [UIFont smallFont];
        _limitTimeLab.text = @"有效期";
    }
    return _limitTimeLab;
}


- (UILabel *)detailLimitTimeLab {
    if (!_detailLimitTimeLab) {
        _detailLimitTimeLab = [[UILabel alloc] init];
        _detailLimitTimeLab.textColor = UIColorFromRGB(0x939393);
        _detailLimitTimeLab.font = [UIFont systemFontOfSize:22];
        _detailLimitTimeLab.text = @"-- -- ----";
    }
    return _detailLimitTimeLab;
}
@end
